package com.share.service.template;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.share.bean.template.Template;
import com.share.commons.base.dao.BaseDaoSupport;

@Component
@Transactional
public class TemplateServiceImpl extends BaseDaoSupport<Template> implements
		TemplateService {

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void deleteTemplate(Object[] ids) throws RuntimeException {
		this.deleteAllObject(Template.class, ids) ;
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public List<Template> findAllTemplate() throws RuntimeException {
		
		String hql = "select o from TemplateBean o" ;
		
		return (List<Template>) this.find(hql);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public Template loadByIdTemplate(int id) throws RuntimeException {
		
		return this.loadById(Template.class, id) ;
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void saveTemplate(Template t) throws RuntimeException {
		t.setAddTime(new Date()) ;
		this.saveObject(t) ;
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void updateTemplate(Template t) throws RuntimeException {
		t.setAddTime(new Date()) ;
		this.updateObject(t) ;
	}

}
